<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('权重计算')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal importFile" enctype="multipart/form-data">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><h4>XXX权重计算</h4></label>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">专家主观权重：</label>
                            <div class="col-sm-2">
                                <input id="expertSubject" name="expertSubject" type="file">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">原始数据矩阵：</label>
                            <div class="col-sm-2">
                                <input id="originalData" name="originalData" type="file">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">正向指标数量：</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="positiveNumber" name="positiveNumber"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">&nbsp;</label>
                            <div class="col-sm-2">
                                <button class="btn btn-primary " type="button" onclick="importFile()">
                                    <i class="fa fa-check"></i>&nbsp;生成
                                </button>
                            </div>
                        </div>
                        <div class="hr-line-dashed downloadDiv"></div>
                        <div class="form-group downloadDiv">
                            <label class="col-sm-1 control-label">&nbsp;</label>
                            <div class="col-sm-2">
                                <button class="btn btn-danger " type="button" onclick="downloadFile()">
                                    <i class="fa fa-download"></i>&nbsp;下载
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    $(function () {
        $(".downloadDiv").hide();
    })

    function importFile() {
        var checkStr = /^\d+$/;
        if ($("#positiveNumber").val().length > 0 && !checkStr.test($("#positiveNumber").val())) {
            $.modal.alertError('请输入非负整数！');
            return false;
        }
        var data = new FormData($(".importFile")[0]);
        $.ajax({
            type: 'post',
            url: "/zhudi/importData",
            cache: false,    //上传文件不需缓存
            processData: false, //需设置为false。因为data值是FormData对象，不需要对数据做处理
            contentType: false, //需设置为false。因为是FormData对象，且已经声明了属性enctype="multipart/form-data"
            data: data,
            dataType: 'json',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess("生成成功，点击下载获取结果");
                    $(".downloadDiv").show();
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function () {
                alert("请求失败")
            }
        })
    }

    function downloadFile() {
        location.href = '/zhudi/downloadData';
    }

</script>
</body>
</html>